#ifndef MATERIAL_H
#define MATERIAL_H


#include "Framework/Prerequisites.h"
#include "IO/Resource.h"
#include "Graphics/Technique.h"
#include "Framework/SharedPtr.h"

namespace tyro
{
	namespace Graphics
	{
		class Material : public IO::Resource
		{ 
		public:

			Material(IO::ResourceManager* resMgr, const String& name, ResourceHandle resHandle, const String& group);

			Technique* CreateTechnique(void);
			Technique* GetTechnique(UINT_16 index);

		protected:

			typedef vector<Technique*>::type Techniques;
			Techniques	techniques;

		private:
		};


		class MaterialPtr : public Framework::SharedPtr<Material>
		{
		public:
			MaterialPtr() : Framework::SharedPtr<Material>() {}
			explicit MaterialPtr(Material* ptr) : Framework::SharedPtr<Material>(ptr) {}
			MaterialPtr(const MaterialPtr& r) : SharedPtr<Material>(r){}
			MaterialPtr(const IO::ResourcePtr& res) : SharedPtr<Material>()
			{
				// Cast data members
				ptr = static_cast<Material*>(res.GetPointer());
				useCount = res.GetUseCountPointer();

				// Increment use counter
				if (useCount)
				{
					++(*useCount);
				}


			}


			// Convert to resource ptr
			MaterialPtr& operator=(const IO::ResourcePtr& res )
			{
				// Check for self
				if(ptr == static_cast<Material*>(res.GetPointer()))
				{
					return *this;
				}

				// Cast data members
				ptr = static_cast<Material*>(res.GetPointer());
				useCount = res.GetUseCountPointer();

				// Increment use counter
				if (useCount)
				{
					++(*useCount);
				}

				return *this;
			}

		};
	}
}

#endif